package com.cryptoneedle.garden.entity.source.constraint;


import cn.hutool.v7.core.bean.BeanUtil;
import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.garden.key.ColumnKey;
import com.cryptoneedle.garden.key.DatabaseKey;
import com.cryptoneedle.garden.key.TableKey;
import com.cryptoneedle.garden.key.source.constraint.ConstraintColumnKey;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

/**
 * <p>description: 源数据源-唯一约束 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "source_constraint_unique")
@IdClass(ConstraintColumnKey.class)
@Comment("源数据源-唯一约束")
public class SourceConstraintUnique extends BaseEntity {

    @Id
    @Comment("源数据源-目录名称")
    private String catalogName;
    @Id
    @Comment("源数据源-数据库名称")
    private String databaseName;
    @Id
    @Comment("源数据源-表名称")
    private String tableName;
    @Id
    @Comment("源数据源-约束名称")
    private String constraintName;
    @Id
    @Comment("源数据源-列名称")
    private String columnName;

    @Comment("源数据源-排序")
    private Integer position;

    /**
     * Key
     */

    public ConstraintColumnKey constraintUniqueKey() {
        return BeanUtil.copyProperties(this, ConstraintColumnKey.class);
    }

    public DatabaseKey databaseKey() {
        return BeanUtil.copyProperties(this, DatabaseKey.class);
    }

    public TableKey tableKey() {
        return BeanUtil.copyProperties(this, TableKey.class);
    }

    public ColumnKey columnKey() {
        return BeanUtil.copyProperties(this, ColumnKey.class);
    }
}